package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: P0148_Sort
 * Description:
 * Author: xyf
 * Date: 9/11/22 10:59 AM
 * Version: 1.0
 **/
public class P0148_Sort
{
    public ListNode sortList(ListNode head)
    {
        int length = 0;
        ListNode tmp = head;
        while (tmp != null)
        {
            length++;
            tmp = tmp.next;
        }

        for (int i = 0; i < length; i++)
        {
            ListNode cur = head;
            for (int j = 0; j < length - i - 1; j++)
            {
                if (cur.val > cur.next.val)
                {
                    ListNode temp = cur.next;
                    cur.next = cur.next.next;
                    temp.next = cur;
                }
            }
        }
        return head;
    }
}
